package com.bskj.kuaifu.service.template.impl;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.bskj.common.bean.model.ParkInfo;
import com.bskj.common.bean.model.ParkingLotCustomer;
import com.bskj.common.bean.model.WechatTemplateMsg;
import com.bskj.common.bean.model.WxTemplateParams;
import com.bskj.common.utils.DateTimeUtil;
import com.bskj.kuaifu.service.IParkingLotCustomerService;
import com.bskj.kuaifu.service.template.TemplateMessageAction;

/**
 * 消费订单通知
 * 
 * @author lishi
 * @date 2018年4月12日 下午12:13:46
 * 
 *{{first.DATA}}
 *订单金额：{{keyword1.DATA}}
 *停车地点：{{keyword2.DATA}}
 *车牌号码：{{keyword3.DATA}}
 *停车时间：{{keyword4.DATA}}
 *扣后余额：{{keyword5.DATA}}
 *{{remark.DATA}}
 *
 */
@Service(value = "payOrderAction")
public class PayOrderAction implements TemplateMessageAction {
	@Autowired
	private IParkingLotCustomerService parkingLotCustomerService;

	public WechatTemplateMsg processMessage(Map<String, Object> paramMap) throws Exception {
		ParkInfo parkInfo = (ParkInfo) paramMap.get("parkInfo");

		ParkingLotCustomer parkingLotCustomer = parkingLotCustomerService.get(parkInfo.getParkLotCustimerId());

		WechatTemplateMsg wechatTemplateMsg = new WechatTemplateMsg();
		WxTemplateParams params = new WxTemplateParams();

		Integer changeCoupon = parkInfo.getChangeCoupon();
		Integer charge = parkInfo.getCharge();

		params.put("first", "您有新的停车消费信息");
		if (changeCoupon > 0) {
			params.put("keyword1", charge / 10 + ".00元（包含" + changeCoupon / 10 + ".00元赠券）");
		} else {
			params.put("keyword1", charge / 10 + ".00元");
		}
		if(parkingLotCustomer != null) {
			params.put("keyword2", parkingLotCustomer.getName());
		} else {
			params.put("keyword2", "未知停车场");
		}
		params.put("keyword3", parkInfo.getCarNo());
		params.put("keyword4", DateTimeUtil.date2String(parkInfo.getOutTime()) + "");
		params.put("keyword5", parkInfo.getAfterMoney() / 10 + ".00元");
		params.put("remark", "\n如扣后余额为负，请您尽快充值结清，方便下次自由进出停车场！");
		wechatTemplateMsg.setData(params);

		return wechatTemplateMsg;
	}
}
